﻿<%@ Control Language="C#" Inherits="DotNetNuke.UI.Skins.Controls.DNNJDMenu" AutoEventWireup="true" Codebehind="DNNJDMenu.ascx.cs" %>
<asp:Literal ID="ltContent" runat="server"></asp:Literal>
<script language="javascript" type="text/javascript">
	<!--
	 jQuery(document).ready
	(function(){
		function addEvents(ul) {
			var settings = jQuery.data( jQuery(ul).parents().andSelf().filter('ul.<%=JDMenu%>')[0], '<%=JDMenu%>Settings' );
			jQuery('> li', ul)
				.bind('mouseenter.<%=JDMenu%> mouseleave.<%=JDMenu%>', function(evt) {
					jQuery(this).toggleClass('jdm_hover');
					var ul = jQuery('> ul', this);
					if ( ul.length == 1 ) {
						clearTimeout( this.jQuerydTimer );
						var enter = ( evt.type == 'mouseenter' );
						var fn = ( enter ? showMenu : hideMenu );
						this.jQuerydTimer = setTimeout(function() {
							fn( ul[0], settings.onAnimate, settings.isVertical );
						}, enter ? settings.showDelay : settings.hideDelay );
					}
				})
				.bind('click.<%=JDMenu%>', function(evt) {
					var ul = jQuery('> ul', this);
					if ( ul.length == 1 && 
						( settings.disableLinks == true || jQuery(this).hasClass('accessible') ) ) {
						showMenu( ul, settings.onAnimate, settings.isVertical );
						return false;
					}
					
					// The user clicked the li and we need to trigger a click for the a
					if ( evt.target == this ) {
						var link = jQuery('> a', evt.target).not('.accessible');
						if ( link.length > 0 ) {
							var a = link[0];
							if ( !a.onclick ) {
								window.open( a.href, a.target || '_self' );
							} else {
								jQuery(a).trigger('click');
							}
						}
					}
					if ( settings.disableLinks || 
						( !settings.disableLinks && !jQuery(this).parent().hasClass('<%=JDMenu%>') ) ) {
						jQuery(this).parent().<%=JDMenu%>Hide();
						evt.stopPropagation();
					}
				})
				.find('> a')
					.bind('focus.<%=JDMenu%> blur.<%=JDMenu%>', function(evt) {
						var p = jQuery(this).parents('li:eq(0)');
						if ( evt.type == 'focus' ) {
							p.addClass('jdm_hover');
						} else { 
							p.removeClass('jdm_hover');
						}
					})
					.filter('.accessible')
						.bind('click.<%=JDMenu%>', function(evt) {
							evt.preventDefault();
						});
		}

		function showMenu(ul, animate, vertical) {
			var ul = jQuery(ul);
			if ( ul.is(':visible') ) {
				return;
			}
			ul.bgiframe();
			var li = ul.parent();
			ul	.trigger('<%=JDMenu%>Show')
				.positionBy({ 	target: 	li[0], 
								targetPos: 	( vertical === true || !li.parent().hasClass('<%=JDMenu%>') ? 1 : 3 ), 
								elementPos: 0,
								hideAfterPosition: true
								});
			if ( !ul.hasClass('jdm_events') ) {
				ul.addClass('jdm_events');
				addEvents(ul);
			}
			li	.addClass('jdm_active')
				// Hide any adjacent menus
				.siblings('li').find('> ul:eq(0):visible')
					.each(function(){
						hideMenu( this ); 
					});
			if ( animate === undefined ) {
				ul.show();
			} else {
				animate.apply( ul[0], [true] );
			}
		}
		
		function hideMenu(ul, animate) {
			var ul = jQuery(ul);
			jQuery('.bgiframe', ul).remove();
			ul	.filter(':not(.<%=JDMenu%>)')
				.find('> li > ul:eq(0):visible')
					.each(function() {
						hideMenu( this );
					})
				.end();
			if ( animate === undefined ) {
				ul.hide()
			} else {
				animate.apply( ul[0], [false] );
			}

			ul	.trigger('<%=JDMenu%>Hide')
				.parents('li:eq(0)')
					.removeClass('jdm_active jdm_hover')
				.end()
					.find('> li')
					.removeClass('jdm_active jdm_hover');
		}
		
		// Public methods
		jQuery.fn.<%=JDMenu%> = function(settings) {
			// Future settings: activateDelay
			var settings = jQuery.extend({	// Time in ms before menu shows
										showDelay: 		50,
										// Time in ms before menu hides
										hideDelay: 		500,
										// Should items that contain submenus not 
										// respond to clicks
										disableLinks:	false
										// This callback allows for you to animate menus
										//onAnimate:	null
										}, settings);
			if ( !jQuery.isFunction( settings.onAnimate ) ) {
				settings.onAnimate = undefined;
			}
			return this.filter('ul.<%=JDMenu%>').each(function() {
				jQuery.data(	this, 
						'<%=JDMenu%>Settings', 
						jQuery.extend({ isVertical: jQuery(this).hasClass('<%=JDMenu %>_vertical') }, settings) 
						);
				addEvents(this);
			});
		};
		
		jQuery.fn.<%=JDMenu%>Unbind = function() {
			jQuery('ul.jdm_events', this)
				.unbind('.<%=JDMenu%>')
				.find('> a').unbind('.<%=JDMenu%>');
		};
		jQuery.fn.<%=JDMenu%>Hide = function() {
			return this.filter('ul').each(function(){ 
				hideMenu( this );
			});
		};

		// Private methods and logic
		jQuery(window)
			// Bind a click event to hide all visible menus when the document is clicked
			.bind('click.<%=JDMenu%>', function(){
				jQuery('ul.<%=JDMenu%> ul:visible').<%=JDMenu%>Hide();
			});
	});

	jQuery(function() {
		jQuery('ul.<%=JDMenu%>').<%=JDMenu%>();
	});
	-->
</script>

